package com.base.myproject.client.busi.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BaseStoreEvent;
import com.base.myproject.client.busi.BaseStoreListener;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.busi.print.Printer;
import com.base.myproject.client.busi.system.PrinterSync;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.system.Env;
import com.base.myproject.client.tools.Debug;
import com.base.myproject.client.ui.BaseBusiLeftPanel;
import com.base.myproject.client.ui.BaseFormPanel;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.base.myproject.client.ui.PrintDialog;
import com.base.myproject.client.ui.celleditor.BaseComboBoxForm;
import com.base.myproject.client.ui.codenamemap.CodeNameMapFactory;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.NumberField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.AggregationRowConfig;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.SummaryType;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.TableData;
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
/**
 * 会员信息，美容美发，注意与NewCcode同步
 * 
 * @author Administrator
 *2010-4-17
 * javazgw@gmail.com
 */
public class CcodePanel extends BaseJDBCPanel implements Listener<BaseEvent>,Printer,BaseStoreListener{
	BaseStore<CcodeBusiObject> store ;
	BaseStore<BusiObject> finacestore;
	BaseGrid<BusiObject> 	finacegrid;
	
	BaseBusiLeftPanel<CcodeBusiObject> basbusileftpanel;
	Button addbutton;
	Button delbutton ;
	Button savebutton ;
	Button addfinace;
	Button printer;
	TextField<String> ccode_t;
	TextField<String> cardno_t;
	TextField<String> icode_t;
	TextField<String> cname_t;
	NumberField addfinacecount;//充值次数，如果充值次数大于0，默认不给编辑，除非在人员管理里面设置了权限
	AddFinace addfinacedialog = new AddFinace();
	BaseFormPanel bfp ;
	
	boolean canchanged = false;//有交易记录的数据不允许更改
	public CcodePanel()
	{
		super();
		init();
	}
	public void init()
	{
		
		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);  
	    centerData.setMargins(new Margins(5, 5, 0, 0));  
//	    this.setHeight("800px");
	   // this.setAutoHeight(true);
		this.setWidth(Window.getClientWidth());
	    this.add(initWeiget(),centerData);
		
		registerMainStore(getStore());
		registerStore(getStore());
	//	 this.setAutoHeight(true);
		this.setBusino(busi);
		this.setWidth("960");
		this.setHeight("900px");
		//this.setHeight(Window.getClientHeight()-200);
		getStore().addBaseStoreListener(BaseStoreEvent.EventType.ROW_CHANGED, this);
		setdefault();
	}
	private void setdefault()
	{
		DateTimeFormat activeFormat = DateTimeFormat
		.getFormat("yyyy-M-d H:mm:ss");
		activeFormat.format(new Date());
		getStore().addDefault("createbcode", Env.getEnvbcode());
		getStore().addDefault("createbname", Env.getEnvname());
		getStore().addDefault("createdate", activeFormat.format(new Date()));
	}
	public ContentPanel initWeiget() 
	{
//		 VerticalPanel vpanle = new VerticalPanel();
//		 HorizontalPanel hpanel = new HorizontalPanel();
//		 hpanel.add(CreateCcodeLeftPanel());
//		 hpanel.add(CreateBcodeForm());
/*		ContentPanel cpanel = new ContentPanel();
		cpanel.add(hpanel);*/
		
//		
	//	this.setScrollMode(Scroll.ALWAYS);
		ContentPanel panel = new ContentPanel();
		panel.setHeaderVisible(false);
//		
//		panel.setLayout(new BorderLayout());
//		BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 250);
//		westData.setSplit(true);
//		westData.setCollapsible(true);
//		westData.setMargins(new Margins(0));
//		BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER);
//		centerData.setMargins(new Margins(0, 0, 0, 0));
//		panel.add(CreateCcodeLeftPanel(), westData);
//		panel.add(CreateCcodeForm(), centerData);
//		
		TableLayout tl = new TableLayout(2);
		
		panel.setLayout(tl);
		TableData tdleft = new TableData();
		tdleft.setRowspan(2);
		tdleft.setColspan(1);
		tdleft.setWidth("250px");
		//tdleft.setHeight("700px");
		
		panel.add(CreateCcodeLeftPanel(),tdleft);
		TableData tdright = new TableData();
		tdright.setRowspan(1);
		tdright.setColspan(1);
		tdright.setVerticalAlign(VerticalAlignment.TOP);
		
		tdright.setMargin(5);
	//	tdright.setWidth("500px");
	//	tdright.setHeight("700px");
		tl.setCellHorizontalAlign(HorizontalAlignment.LEFT);
		tl.setCellVerticalAlign(VerticalAlignment.TOP);
		tl.setHeight("680px");
	
		tl.setCellSpacing(5);
		CreateFinaceGrid();
		VerticalPanel vpanel = new VerticalPanel();
		CreateButton();
//		vpanel.add(CreateButton());
		vpanel.add(CreateCcodeForm());
		vpanel.add(CreateCodeFromadv());
		vpanel.add(finacegrid);
		panel.add(vpanel,tdright);
		panel.setScrollMode(Scroll.AUTO);
		return panel;
		
	}
	public void complete()
	{
	
		//工具栏菜单
		getToolbarll().add(addbutton);
		getToolbarll().add(delbutton);
		//getToolbarll().add(savebutton);
		//getToolbarll().add(addfinace);
		getToolbarll().add(printer);
	//	initToolBarItems();
		super.complete();
	}
	 public ContentPanel CreateCcodeLeftPanel() {
			List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
			ColumnConfig ccode = new ColumnConfig("s_cardno", "卡号", 50);
		

			columns.add(ccode);
			columns.add(new ColumnConfig("cname", "名字", 70));
			columns.add(new ColumnConfig("s_mobil", "电话", 80));
			//columns.add(new ColumnConfig("s_sex", "性别", 50));

		//	ColumnModel cm = new ColumnModel(columns);

			// --set modetype
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("icode");
			type.addField("ccode");
			type.addField("cname");
			type.addField("s_cardno");
			type.addField("s_sex");
			type.addField("s_edu");
			type.addField("s_birid");
			type.addField("s_mobil");
			type.addField("s_idno");
			type.addField("s_mark");
			type.addField("password");
			
			type.addField("addfinacecount");
			type.addField("createbname");
			type.addField("createdate");
			type.addField("updatebname");
			type.addField("updatedate");
			
			

			type.getField("s_cardno").setType(String.class);
			type.getField("s_sex").setType(Integer.class);

			type.getField("s_edu").setType(String.class);
			type.getField("s_birid").setType(Date.class);

			type.getField("s_mobil").setType(String.class);
			type.getField("s_idno").setType(String.class);
			type.getField("s_mark").setType(String.class);
			type.getField("addfinacecount").setType(Integer.class);
			// type.addField("Phone");
			// type.addField("imagepath");
			StoreInfo info = new StoreInfo();
			info.setTablename("ccode");
			//info.setLimit("200");
			info.setSql("select * ,case when (select count(*) from bcode where bcode='"+Env.getEnvbcode()+"' and caneditccode =1 )=1 then 0 else (select count(*) from s_service_finance where s_service_finance.ccode = ccode.ccode) end as addfinacecount from ccode where s_cardno is not null order by s_cardno");
			info.setKeyname(new String[] { "icode" });
			//使用了第二种模式，见store的read
			 basbusileftpanel = new BaseBusiLeftPanel<CcodeBusiObject>(columns,
					type, info,false,false,2);
			setStore(basbusileftpanel.getStore());
			//getStore().setKeyname(new String[] { "codename" });

			basbusileftpanel.getGrid().setAutoExpandColumn("s_mobil");
			setMaincomponent(basbusileftpanel.getGrid());
			return basbusileftpanel.getPanel();
		}
	 
	 /**
	  * 创建高级的panel，主要是不常用的系统信息
	  * @return
	  */
	 BaseFormPanel CreateCodeFromadv()
	 {
		 FieldSet fieldSet = new FieldSet();  
		 fieldSet.setHeading("高级");  
		 fieldSet.setCollapsible(true);
		 fieldSet.setExpanded(false);
		 fieldSet.setLayout(new TableLayout(4));
		 
		 
		 BaseFormPanel bfpadv = new BaseFormPanel(getStore());
		 Label createbname_l = new Label("创建人员");
			Label createdate_l = new Label("创建日期");
			Label updatebname_l = new Label("最后更新人员");
			Label updatedate_l = new Label("最后更新日期");
			
			TextField<String> createbname_t = new TextField<String>();
			TextField<String> createdate_t = new TextField<String>();
			TextField<String> updatebname_t = new TextField<String>();
			TextField<String> updatedate_t = new TextField<String>();
			
			updatedate_t.setEnabled(false);
			updatebname_t.setEnabled(false);
			createdate_t.setEnabled(false);
			createbname_t.setEnabled(false);
			
			
			createbname_t.setName("createbname");
			createdate_t.setName("createdate");
			updatebname_t.setName("updatebname");
			updatedate_t.setName("updatedate");
			
			TableLayout tl = new TableLayout(4);
			tl.setWidth("600");
			bfpadv.setLayout(tl);
			TableData td=new TableData();
			td.setColspan(1);
		//	td.setWidth("2000");
			td.setMargin(100);
			td.setPadding(5);
			td.setRowspan(1);
			
			fieldSet.add(createbname_l,td);
			fieldSet.add(createbname_t,td);
			fieldSet.add(createdate_l,td);
			fieldSet.add(createdate_t,td);
			fieldSet.add(updatebname_l,td);
			fieldSet.add(updatebname_t,td);
			fieldSet.add(updatedate_l,td);
			fieldSet.add(updatedate_t,td);
			
			bfpadv.add(fieldSet,td);
			bfpadv.inited();
			
			bfpadv.setHeaderVisible(false);
		 return bfpadv;
	 }
	 BaseFormPanel CreateCcodeForm()
	{
			 bfp = new BaseFormPanel(getStore());
			Label cardno_l = new Label("卡号");
			cardno_l.setWidth("50");
			Label cname_l = new Label("名字");
			cname_l.setWidth("50");
			Label sex_l = new Label("性别");
			sex_l.setWidth("50");
			Label edu_l = new Label("学历");
			Label bird_l = new Label("出生日期");
			
			Label mobil_l = new Label("手机号");
			Label idno_l = new Label("身份证号");
			Label mark_l = new Label("备注");
			Label password_l = new Label("密码");
			
			cardno_t = new TextField<String>();
			cardno_t.setAllowBlank(false);
			cardno_t.addListener(Events.Change, this);
			cname_t = new TextField<String>();
			cname_t.setAllowBlank(false);
			//TextField<String> sex_t = new TextField<String>();
			//BaseGridEditor sex_t= CodeNameMapFactory.aa();
			BaseComboBoxForm<BaseModelData> sex_t = CodeNameMapFactory.createSexInput_F();
			TextField<String> edu_t = new TextField<String>();
			//CodeNameMapFactory codenamemap = new CodeNameMapFactory();
			
			//BaseGridEditor<String> edu_t  =codenamemap.createSexInput_G();
			
			
		//	createBocdeInput_F
			DateField bird_t = new DateField();
			bird_t.setAutoWidth(true);
			
			 bird_t.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d H:mm:ss"));  
			TextField<String> mobil_t = new TextField<String>();
			mobil_t.setAllowBlank(false);
			TextField<String> idno_t = new TextField<String>();
			TextField<String> mark_t = new TextField<String>();
			TextField<String> password_t = new TextField<String>();
			
			
			
		
			 addfinacecount = new NumberField();
			
			password_t.setPassword(true);
		//	password_t.setToolTip("将光标放到此处，并由会员录入自己的密码");
			ccode_t = new TextField<String>();
		//	ccode_t.setEnabled(false);
			ccode_t.setVisible(false);
			 icode_t = new TextField<String>();
			icode_t.setVisible(false);
			
			cardno_t.setName("s_cardno");
			cname_t.setName("cname");
			password_t.setName("password");
			
			sex_t.setName("s_sex");
			edu_t.setName("s_edu");
			bird_t.setName("s_birid");
			mobil_t.setName("s_mobil");
			idno_t.setName("s_idno");
			mark_t.setName("s_mark");
			ccode_t.setName("ccode");
			icode_t.setName("icode");
			
			
		
			this.setHeight("200");
			TableLayout tl = new TableLayout(4);
			tl.setWidth("600");
			bfp.setLayout(tl);
			TableData td=new TableData();
			td.setColspan(1);
		//	td.setWidth("2000");
			td.setMargin(100);
			td.setPadding(5);
			td.setRowspan(1);
			
			bfp.add(cardno_l,td);
			bfp.add(cardno_t,td);
			bfp.add(cname_l,td);
			bfp.add(cname_t,td);

			
			
			bfp.add(mobil_l,td);
			bfp.add(mobil_t,td);
			bfp.add(sex_l,td);
			bfp.add(sex_t,td);
			bfp.add(edu_l,td);
			bfp.add(edu_t,td);
			bfp.add(bird_l,td);
			bfp.add(bird_t,td);

			
			bfp.add(idno_l,td);
			bfp.add(idno_t,td);
			bfp.add(mark_l,td);
			bfp.add(mark_t,td);
			
		
			
			
			bfp.add(ccode_t,td);
			bfp.add(icode_t,td);
			//bfp.add(addfinacecount,td);
			
//			bfp.add(password_l,td);
//			bfp.add(password_t,td);
			
		//	bfp.add(hpanel,td);
			bfp.inited();
			return bfp;
	}
	 
	 void CreateFinaceStore(){
			
			ModelType type = new ModelType();
			type.setRoot("records");
			type.setRecordName("record");
			type.setTotalName("totle");
			type.addField("icode");
			type.addField("ccode");
			type.addField("finance");
			type.addField("updatedate");
			type.addField("dc");
			
			type.addField("name");
			type.getField("finance").setType(Double.class);
			//type.getField("dc").setType(Integer.class);
			// type.addField("Phone");
			// type.addField("imagepath");
			StoreInfo info = new StoreInfo();
			info.setTablename("s_service_finance");
			
			
//			String sql = " select  finance*dc as finance,ccode,updatedate,case when dc=1 then "+URL.encode("'充'")+" else "+URL.encode("'扣'")+" end as dc from s_service_finance where ccode ='{ccode}' ";
//			sql +=" union all ";
//			sql +=" select  paid*-1 as finance,ccode,serviceenddate as updatedate,"+URL.encode("'扣'")+" as dc from s_service_po where  check_isas=1 and busistatus=524288  and ccode ='{ccode}' order by updatedate desc ";

			String sql ="";

			sql += " select * ";
			sql += " from "; 
			sql += " ( ";
			sql += " select  finance*dc as finance,ccode,updatedate,case when dc=1 then "+URL.encode("'充'")+" else "+URL.encode("'扣'")+" end as dc,bcode ";

			sql += " from s_service_finance where ccode ='{ccode}' "; 
			sql += " ) as a ";
			sql += " left join  ";
			sql += " (select (select name from systeminfo where systeminfo.id = bcode.systemid) %2B'-'%2B bname as name,bcode from bcode) as b ";
			sql += " on  ";
			sql += " a.bcode = b.bcode ";

			sql += " union all "; 

			sql += " select * from ";
			sql += " ( ";
			sql += " select  paid*-1 as finance,ccode,serviceenddate as updatedate,"+URL.encode("'扣'")+" as dc ,bcode from s_service_po where  busistatus=524288  and ccode ='{ccode}' "; 
			sql += " ) as a ";
			sql += " left join  ";
			sql += " (select (select name from systeminfo where systeminfo.id = bcode.systemid) %2B'-' %2B bname as name,bcode from bcode) as d ";
			sql += " on  ";
			sql += " a.bcode = d.bcode ";
			sql += " order by updatedate desc "; 
			
			
			//info.setSql("select * from s_service_finance where ccode='{ccode}'");
			info.setSql(sql);
			info.setParent(getStore());
			info.setNeedAllRow("no");
			info.setLinkparentcolumns(new String[]{"ccode"});
			info.setLinkparent_chile_columns(new String[]{"ccode"});
			info.setKeyname(new String[] { "icode" });
			
			 finacestore = new BaseStore<BusiObject>(type,info);

		
		}
	 void CreateFinaceGrid()
	 {
		 CreateFinaceStore();
		 CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
			List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
			columns.add(cbs.getColumn());
			
			
			ColumnConfig c1 = new ColumnConfig("updatedate", "发生日期", 200);
		//	TextField<String> c1t = new TextField<String>();
		//	c1.setEditor(new CellEditor(c1t));
			
			ColumnConfig c2 = new ColumnConfig("finance", "金额", 100);
			// TextField<String> uprictext = new TextField<String>();
			// upric.setEditor(new CellEditor(uprictext));
//			c2.setAlignment(HorizontalAlignment.RIGHT);
//			c2.setNumberFormat(NumberFormat.getCurrencyFormat());
//			c2.setEditor(new CellEditor(new NumberField()));
//			c2.getEditor().getField().setName("finance");
		//	upric.getEditor().getField().addListener(Events.Change, this);
			//upric.getEditor().addListener(Events.Complete, this);
		
			ColumnConfig c3 = new ColumnConfig("dc", "类型", 100);
//			NumberField c3t = new NumberField();
//			c3.setEditor(new CellEditor(c3t));
			
			columns.add(c1);
			columns.add(c2);
			columns.add(c3);
			columns.add(new ColumnConfig("name", "操作人员", 150));
//			columns.add(new ColumnConfig("dc", "类型", 100));
			ColumnModel cm = new ColumnModel(columns);
			
			AggregationRowConfig averages = new AggregationRowConfig();
			averages.setHtml("updatedate", "合计：");
			
			averages.setSummaryType("finance", SummaryType.SUM);
			averages.setSummaryFormat("finance", NumberFormat.getCurrencyFormat());
			
			
			 
		
			 cm.addAggregationRow(averages);
			finacegrid = new BaseGrid<BusiObject>(finacestore, cm,false,false,null);
			finacegrid.setWidth("680");
			finacegrid.setHeight("230");
			

		
			cbs.setSelectionMode(SelectionMode.SINGLE);
			finacegrid.setSelectionModel(cbs);
			//finacegrid.setEnabled(false);
	 }
	 void CreateButton()
	 {
			
			 addbutton = new Button("添加新会员");
			 delbutton = new Button("删除此会员");
			 savebutton = new Button("保存会员信息");
			 addfinace= new Button("充值");
			 printer= new Button("打印");
			 
			 addfinace.setIconStyle("money_yen");
			 
		
			addbutton.setIconStyle("associator");
			delbutton.setIconStyle("icon-delete");
			printer.setIconStyle("printer");
			
			addbutton.addListener(Events.Select, this);
			delbutton.addListener(Events.Select, this);
			savebutton.addListener(Events.Select, this);
			addfinace.addListener(Events.Select, this);
			printer.addListener(Events.Select, this);
			
	 }
		/**
		 * @return the store
		 */
		public BaseStore<CcodeBusiObject> getStore() {
			return store;
		}
		/**
		 * @param store the store to set
		 */
		public void setStore(BaseStore<CcodeBusiObject> store) {
			this.store = store;
		}
		@Override
		public void handleEvent(BaseEvent be) {
			
			if(be.getSource().equals(addbutton))
			{
				//basbusileftpanel.getGrid().addnewrecord();
				//特殊用法
				
				basbusileftpanel.getGrid().stopEditing();  
				HashMap hm = new HashMap();

				CcodeBusiObject jdbcml = new CcodeBusiObject(hm);
				getStore().add(jdbcml);
				basbusileftpanel.getGrid().getSelectionModel().select(jdbcml, false);
			}
			else if(be.getSource().equals(delbutton))
			{
				MessageBox.info("", "你不能删除会员信息", null);
			//	basbusileftpanel.getGrid().deleterecord();
			}
			else if(be.getSource().equals(savebutton))
			{
				getStore().trySave();
			}
			else if(be.getSource().equals(addfinace))
			{
				Object ccode =getStore().getValue("ccode");
				addfinacedialog.setCcode(ccode==null?null:ccode.toString());
				addfinacedialog.showDialog();
			}
			else if(be.getSource().equals(printer))
			{
				Print() ;
			}
			if (be.getType() == Events.Change)
			{
				
				String name = ((FieldEvent) be).getField().getName();
				Debug.printf(name);
				if (name.equals("s_cardno")) {
					ccode_t.setFireChangeEventOnSetValue(true);
					ccode_t.setValue(icode_t.getValue());
					ccode_t.setFireChangeEventOnSetValue(false);
				} 
			}
		}
		
		@Override
		public void Print() { 
			
			
			Object icode =getStore().getValue("icode");
			
			if(icode==null)
			{
				MessageBox.alert("错误", "请选择要打印的会员", null);
				return;
			}
			PrinterSync printersync = new PrinterSync();
			printersync.setBcode(Env.getEnvbcode());
			printersync.setPrintcode("service_1001");
			printersync.setIcode(icode+"");
			final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
			.create(com.base.myproject.client.tools.GreetingService.class);
			greetingService.getPrinterHtml(printersync,new AsyncCallback<String>(){

				@Override
				public void onFailure(Throwable caught) {
					
					
				}

				@Override
				public void onSuccess(String result) {
					Debug.printf(result.toString());
					PrintDialog print = new PrintDialog("", "", result);
				}
				
			});
			
//			String cardno = "";
//		
//			DateTimeFormat d = DateTimeFormat.getFormat("yyyy-M-d h:mm:ss");
//
//			String str = "";
//			str += "<table cellpadding=\"3\">";
//			str += "<tr>";
//			str += "<td colspan=\"2\" align=\"center\"><span><U><strong>"+SystemInfo.getInstance().getTitle()+"</strong></U></span></td>";
//			str += "</tr>";
//			str += "<tr>";
//			str += "<td width=\"180\"><span>卡号:</span>"+cardno_t.getValue()+"</td>";
//			str += "<td><span>顾客:</span>"+cname_t.getValue()+"</td>";
//			str += "</tr>";
//	 
//
//			str += "<tr>";
//			
//			
//			double dd = 0;
//			if(html.getValue()!=null)
//			{
//				dd=html.getValue().doubleValue()-Paid.getValue().doubleValue();
//			}
//			str += "<td colspan=\"2\" align=\"left\"><span>会员卡余额:</span>"+(dd)+"</td>";
//			str += "</tr>";
////			str += "<tr>";
////			str += "<td colspan=\"2\"><span>开始时间:</span><span class=\"dateFormat\">"+d.format(servicestartdate.getValue())+"</span></td>";
////			str += "</tr>";
////			
//			str += "<tr>";
//			str += "<td colspan=\"2\"><span>时间:</span><span class=\"dateFormat\">"+d.format(createdate.getValue())+"</span></td>";
//			str += "</tr>";
//			str += "<tr>";
//			str += "<td colspan=\"2\"><span>操作员:</span><span >"+Env.getEnvname()+"</span></td>";
//			str += "</tr>";
////		 
//			//---
//			str += "<tr>";
//			str += "<td colspan=\"2\">";
//			
//			str += "<table class=\"tblprice\">";
//			
//			//标题
//			str += "<tr style=\"\">";
//			str += "<th width=\"250\">名称</th>";
//			str += "<th width=\"120\">数量</th>";
//			str += "<th>金额</th>";
//			str += "</tr>";
//			
//			//循环
////			str += "<tr>";
////			str += "<td>洗发水</td><td>2</td><td width=\"200\">20</td>";
////			str += "</tr>";
////			
////			str += "<tr>";
////			str += "<td>洗脚水</td><td>2</td><td width=\"200\">40</td>";
////			str += "</tr>";
//			for(BusiObject bu:s_service_po_g_store.getModels())
//			{
//				str += "<tr>";
//				str += "<td>"+bu.get("serviceitem")+"</td><td>"+bu.get("qty")+"</td><td width=\"200\">"+bu.get("total")+"</td>";
//				str += "</tr>";
//			}
//			
//			
//			str += "</table>";
//			
//			str += "</td>";
//			str += "</tr>";
//			
//		
//			//---
//			
////			str += "<tr>";
////			str += "<td align=\"right\" colspan=\"3\" style=\"border-top:1px solid #000\">合计金额:60</td>";
////			str += "</tr>";
//			
//			str += "<tr>";
//			str += "<td><span>应收款:</span>"+Accounts.getValue()+"</td>";
//			str += "<td><span>实收款:</span>"+Paid.getValue()+"</td>";
//			str += "</tr>";
//			str += "<tr>";
//			str += "<td colspan=\"2\" align=\"left\"><span>"+SystemInfo.getInstance().getName()+"</span></td>";
//			
//			str += "</tr>";
//			
//			
//			str += "<tr>";
//			
//			str += "<td colspan=\"2\" align=\"left\" ><span>电话:</span>"+SystemInfo.getInstance().getTel()+"</td>";
//			str += "</tr>";
//			
//			str += "<tr>";
//			str += "<td colspan=\"2\" align=\"center\"><span>"+SystemInfo.getInstance().getSlogan()+"</span></td>";
//			str += "</tr>";
//			str += "</table>";
//			PrintDialog print = new PrintDialog("", "/gwtbase/css/print.css", str);
//			
//			
		}
		@Override
		public void BaseStoreEventHandle(BaseStoreEvent evt) {
			if(evt.getEventType()==BaseStoreEvent.EventType.ROW_CHANGED)
			{
				Object addfinacecount = evt.getBasestore().getValue("addfinacecount");
				//if(addfinacecount==null)
					
				//Debug.printf("addfinacecount="+addfinacecount+"--"+(!addfinacecount.toString().equals("0"))+"addfinacecount"+addfinacecount.getClass());
				if(addfinacecount==null || addfinacecount.toString().equals("0"))
				{
					setEnableed(true);
				}
				else
				{
					setEnableed(false);
				}
			}
			
		}
		/**
		 * false 不能被编辑
		 * 
		 * @param b
		 */
		void setEnableed(boolean b)
		{
			
			bfp.setEnabled(b);
			
		}
		
		BaseComboBoxForm<BaseModelData> createBcode_filter()
		{
			
			BaseStore<BaseModelData> base_filter;
				ModelType type = new ModelType();
				type.setRoot("records");
				type.setRecordName("record");
				type.setTotalName("totle");
				type.addField("code");
				type.addField("name");
				StoreInfo info = new StoreInfo();
				info.setTablename("bcode");
				info.setNeedAllRow("no");
				info.setForcenolimit("true");
				info.setSql("select bcode as code,bname as name from bcode where bcode is not null and bname is not null and systemid in (select systemid from bcode where bcode= '"+Env.getEnvbcode()+"')");
				base_filter = new BaseStore<BaseModelData>(type,info);
		
			BaseComboBoxForm<BaseModelData> bcbf = new BaseComboBoxForm<BaseModelData>(base_filter);
			return bcbf;
		}
}
